// 分析url地址 内置的
// const url = require('url')

// let href = 'https://new.qq.com/omn/20210516/20210516A09D5P00.html?id=100#hash'
// let href = '//new.qq.com/omn/20210516/20210516A09D5P00.html?id=100#hash'
// let href = '/omn/20210516/20210516A09D5P00.html?id=100#hash'

// 参数1：分析url地址
// 参数2：boolean true为query属性转为对象，false字符串
// 参数3：一般不用 boolean true时，在url地址没有写协议时，还可以获取主机名
// console.log(url.parse(href, true, true));
// console.log(url.parse(href, true));
/* const { pathname, query } = url.parse(href, true)
console.log(pathname, query); */

// URL js内置

// let href = 'https://new.qq.com/omn/20210516/20210516A09D5P00.html?id=100&name=lisi#hash'
// getAll()
// let href = 'https://new.qq.com/omn/20210516/20210516A09D5P00.html?id=100&id=200&name=lisi#hash'
// 全部的get数据
let href = 'https://new.qq.com/omn/20210516/20210516A09D5P00.html?id=100&name=lisi#hash'
const url = new URL(href);
// console.log(url.searchParams);
// console.log(url.searchParams.get('id'));
// console.log(url.searchParams.get('name'));

// 获取query中相同名称的数据 以数组形返回
// console.log(url.searchParams.getAll('id'));

// 获取全部的get数据
// console.log(url.searchParams.entries());
for (let [key, value] of url.searchParams.entries()) {
  console.log(key, value);
}


/* let href = '?id=100&name=lisi#hash'
const query = new URLSearchParams(href)
// search对象 key => value
console.log(query); */
